package com.bdqn.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.crm.pojo.SalChance;
import com.bdqn.crm.pojo.SalPlan;
import com.bdqn.crm.service.SalPlanService;
import com.bdqn.crm.utils.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/plan")
public class SalPlanController {

    @Resource
    private SalPlanService salPlanService;


    @RequestMapping("/list")
    public String list(HttpServletRequest request, Model model, @RequestParam(value = "svrCustName",required = false) String custName, @RequestParam(value = "svrDueTo",required = false) String DueTo,@RequestParam(value = "svrTitle",required = false) String title, @RequestParam(required = false, defaultValue = "1") int pageIndex){
        Page<SalPlan> page = new Page<>(pageIndex, 5);

        if (salPlanService.count(custName,DueTo,title) == 0) {     //此操作说明 数据库没有数据可展示，那么就全部清零
            page.setTotalElements(0);
            page.setContent(null);
        } else {
            page.setTotalElements(salPlanService.count(custName,DueTo,title));
            page.setContent(salPlanService.selectPages(custName, DueTo, title, (page.getNumber() - 1) * page.getPageSize(), page.getPageSize()));
        }
        model.addAttribute("svrCustName",custName);
        model.addAttribute("svrDueTo",DueTo);
        model.addAttribute("svrTitle",title);
        model.addAttribute("planPage", page);
        return "plan/list";
    }

}
